Print the first N rows of Pascal’s triangle¶
Write a python function that prints out the first N rows of Pascal’s triangle.
Note :
Pascal’s triangle is an arithmetic and geometric
figure first imagined by Blaise Pascal.
Sample Pascal’s triangle :
Each number is the two numbers above it added together
def pascal_triangle(N):
trow = [1]
y = [0]
for x in range(max(N, 0)):
print(trow)
trow = [l + r for l, r in zip(trow + y, y + trow)]
return n >= 1
# test
pascal_triangle(6)
Output:
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]